﻿using System;
using System.Collections;
using mojoPortal.Web.Framework;

namespace ud_SwirlingQuestion
{
    /// <summary>
    /// encapsulates the feature instance configuration loaded from module settings into a more friendly object
    /// </summary>
    public class SwirlingQuestionConfiguration
    {
        public SwirlingQuestionConfiguration()
        { }

        public SwirlingQuestionConfiguration(Hashtable settings)
        {
            LoadSettings(settings);

        }

        private void LoadSettings(Hashtable settings)
        {
            if (settings == null) { throw new ArgumentException("must pass in a hashtable of settings"); }

            if (settings.Contains("CustomCssClassSetting")) { customCssClass = settings["CustomCssClassSetting"].ToString(); }
            usePaging = WebUtils.ParseBoolFromHashtable(settings, "UsePagingSetting", usePaging);
            pageSize = WebUtils.ParseInt32FromHashtable(settings, "PageSizeSetting", pageSize);
            showOthers = WebUtils.ParseBoolFromHashtable(settings, "ShowOthersSetting", showOthers);
            useLinkForHeading = WebUtils.ParseBoolFromHashtable(settings, "UseLinkForHeadingSetting", useLinkForHeading);
            titleOnly = WebUtils.ParseBoolFromHashtable(settings, "TitleOnlySetting", titleOnly);
            othersPageSize = WebUtils.ParseInt32FromHashtable(settings, "OthersPageSizeSetting", othersPageSize);
            maxCharsInTitle = WebUtils.ParseInt32FromHashtable(settings, "MaxCharsInTitleSetting", maxCharsInTitle);
            othersUsePaging = WebUtils.ParseBoolFromHashtable(settings, "OthersUsePagingSetting", othersUsePaging);
            othersDetailPageSize = WebUtils.ParseInt32FromHashtable(settings, "OthersDetailPageSizeSetting", othersDetailPageSize);
            showQuestionAuthor = WebUtils.ParseBoolFromHashtable(settings, "ShowQuestionAuthorSetting", showQuestionAuthor);
            if (settings.Contains("DateTimeFormatSetting")) { dateTimeFormat = settings["DateTimeFormatSetting"].ToString(); }
            useExcerpt = WebUtils.ParseBoolFromHashtable(settings, "UseExcerptSetting", useExcerpt);
            if (settings.Contains("ExcerptSuffixSetting")) { excerptSuffix = settings["ExcerptSuffixSetting"].ToString(); }
            excerptLength = WebUtils.ParseInt32FromHashtable(settings, "ExcerptLengthSetting", excerptLength);
            if (settings.Contains("MoreLinkTextSetting")) { moreLinkText = settings["MoreLinkTextSetting"].ToString(); }
            showBottomPanelSetting = WebUtils.ParseBoolFromHashtable(settings, "ShowBottomPanelSetting", showBottomPanelSetting);
            showTopPanelSetting = WebUtils.ParseBoolFromHashtable(settings, "ShowTopPanelSetting", showTopPanelSetting);
            showLeftPanelSetting = WebUtils.ParseBoolFromHashtable(settings, "ShowLeftPanelSetting", showLeftPanelSetting);
            showRightPanelSetting = WebUtils.ParseBoolFromHashtable(settings, "ShowRightPanelSetting", showRightPanelSetting);
            showNumberModuleSetting = WebUtils.ParseInt32FromHashtable(settings, "ShowNumberModuleSetting", showNumberModuleSetting);
            if (settings.Contains("OtherQASetting")) { otherQA = settings["OtherQASetting"].ToString(); }
            usePostQuestionInListSetting = WebUtils.ParseBoolFromHashtable(settings, "UsePostQuestionInListSetting", usePostQuestionInListSetting);
            usePostQuestionInTitleControlSetting = WebUtils.ParseBoolFromHashtable(settings, "UsePostQuestionInTitleControlSetting", usePostQuestionInTitleControlSetting);
            showTweetThisLink = WebUtils.ParseBoolFromHashtable(settings, "ShowTweetThisLinkSetting", showTweetThisLink);
            useFacebookShareButton = WebUtils.ParseBoolFromHashtable(settings, "UseFacebookShareButtonSetting", useFacebookShareButton);
            useGoogleBookmarkButton = WebUtils.ParseBoolFromHashtable(settings, "UseGoogleBookmarkButtonSetting", useGoogleBookmarkButton);
            if (settings.Contains("SearchWatermarkTextSettings")) { searchWatermarkText = settings["SearchWatermarkTextSettings"].ToString(); }
            if (settings.Contains("ResultCssSetting")) { resultCss = settings["ResultCssSetting"].ToString(); }
            if (settings.Contains("SearchButtonTextSetting")) { searchButtonText = settings["SearchButtonTextSetting"].ToString(); }
            if (settings.Contains("ModuleLoaderSetting")) { moduleLoader = settings["ModuleLoaderSetting"].ToString(); }
            showSearchPlace = WebUtils.ParseBoolFromHashtable(settings, "ShowSearchPlaceSetting", showSearchPlace);
        }

        private string customCssClass = string.Empty;
        public string CustomCssClass { get { return customCssClass; } }

        private string resultCss = string.Empty;
        public string ResultCss { get { return resultCss; } }

        private string searchWatermarkText = "Search";
        public string SearchWatermarkTextSettings { get { return searchWatermarkText; } }

        private string searchButtonText = string.Empty;
        public string SearchButtonTextSettings { get { return searchButtonText; } }

        private bool showOthers;
        public bool ShowOthers { get { return showOthers; } }

        private bool usePaging;
        public bool UsePaging { get { return usePaging; } }

        private int pageSize = 10;
        public int PageSize { get { return pageSize; } }

        private int othersDetailPageSize = 10;
        public int OthersDetailPageSize { get { return othersDetailPageSize; } }

        private int othersPageSize = 5;
        public int OthersPageSize { get { return othersPageSize; } }

        private bool othersUsePaging;
        public bool OthersUsePaging { get { return othersUsePaging; } }

        private bool useLinkForHeading;
        public bool UseLinkForHeading { get { return useLinkForHeading; } }

        private bool titleOnly;
        public bool TitleOnly { get { return titleOnly; } set { titleOnly = value; } }

        private bool showQuestionAuthor;
        public bool ShowQuestionAuthor { get { return showQuestionAuthor; } }

        private int maxCharsInTitle = 100;
        public int MaxCharsInTitle { get { return maxCharsInTitle; } }

        private string dateTimeFormat = string.Empty;
        public string DateTimeFormat { get { return dateTimeFormat; } }

        private bool useExcerpt = true;
        public bool UseExcerpt { get { return useExcerpt; } }

        private string excerptSuffix = "...";
        public string ExcerptSuffix { get { return excerptSuffix; } }

        private int excerptLength = 250;
        public int ExcerptLength { get { return excerptLength; } }

        private string moreLinkText = "Detail";
        public string MoreLinkText { get { return moreLinkText; } }

        private bool showBottomPanelSetting = true;
        public bool ShowBottomPanelSetting { get { return showBottomPanelSetting; } }

        private bool showTopPanelSetting = true;
        public bool ShowTopPanelSetting { get { return showTopPanelSetting; } }

        private bool showLeftPanelSetting = true;
        public bool ShowLeftPanelSetting { get { return showLeftPanelSetting; } }

        private bool showRightPanelSetting = true;
        public bool ShowRightPanelSetting { get { return showRightPanelSetting; } }

        private int showNumberModuleSetting;
        public int ShowNumberModuleSetting { get { return showNumberModuleSetting; } }

        private string otherQA = string.Empty;
        public string OtherQA { get { return otherQA; } }

        private bool usePostQuestionInListSetting = true;
        public bool UsePostQuestionInListSetting { get { return usePostQuestionInListSetting; } }

        private bool usePostQuestionInTitleControlSetting = true;
        public bool UsePostQuestionInTitleControlSetting { get { return usePostQuestionInTitleControlSetting; } }

        private bool showTweetThisLink;
        public bool ShowTweetThisLink { get { return showTweetThisLink; } }

        private bool useFacebookShareButton;
        public bool UseFacebookShareButton { get { return useFacebookShareButton; } }

        private string moduleLoader;
        public string ModuleLoader { get { return moduleLoader; } }

        private bool useGoogleBookmarkButton;
        public bool UseGoogleBookmarkButton { get { return useGoogleBookmarkButton; } }

        private bool showSearchPlace;
        public bool ShowSearchPlace { get { return showSearchPlace; } }
    }
}